<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('项目名字')" prop="dealName">
            <!-- <el-input v-model="form.dealName" :placeholder="$t('项目名字')" /> -->
            <template>
              <router-link
                target="_blank"
                :to="{path:'/deal/home/dealBaseHome',query:{id:form.dealId,companyId:form.companyId}}"
                class="link_a"
              >{{ form.dealName }} </router-link>
            </template>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
          <el-form-item :label="$t('项目id')" prop="dealId">
            <el-input v-model="form.dealId" :placeholder="$t('项目id')" show-word-limit maxlength="32" />
          </el-form-item>
        </el-col> -->
        <el-col :span="12">
          <el-form-item :label="$t('标的公司名称')" prop="companyId">
            <!-- <el-input v-model="form.companyId" :placeholder="$t('公司id')" /> -->
            <template>
              <router-link
                target="_blank"
                :to="{path:'/company/base/companyBaseHome',query:{companyId:form.companyId}}"
                class="link_a"
              >{{ form.companyName }}</router-link>
            </template>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('团队成员')" prop="teamMember">
            <!-- <el-input v-model="form.teamMember" :placeholder="$t('团队成员')" /> -->
            <UserSelect
              v-model="form.teamMember"
              :placeholder="$t('团队成员')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('本人或家庭成员担任标的公司职位')" prop="companyPost">
            <el-input v-model="form.companyPost" :placeholder="$t('本人或家庭成员担任标的公司职位')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('申请说明')" prop="explain">
            <el-input v-model="form.content" type="textarea" :placeholder="$t('申请说明')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <FileTable :list.sync="form.fileList" data-type="deal:affiliated:party" :btn-show="!otherBtnHide" />
        </el-col>
      </el-row>
    </el-form>
    <!-- <div slot="footer" class="dialog-footer" style="text-align: right;">
      <save-btn has-permi="system:party" />
    </div> -->
  </div>
</template>

<script>
import { saveDealAffiliatedParty, getDealAffiliatedParty } from '@/api/deal/affiliated/dealAffiliatedParty'
import { getByWfNodeId } from '@/api/deal/form/dealWfGeneral'
   export default {
        data() {
            return {
                otherBtnHide: false,
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                    teamMember: [{ required: true, message: '必填信息', trigger: 'blur' }],
                    companyPost: [{ required: true, message: '必填信息', trigger: 'blur' }]
                }
            }
        },
        created() {
        },
           mounted() {
            this.$bus.$emit('async_done')
          },
        methods: {
            // 初始化数据
            init(data) {
                this.loading = true
                    if (data != null && data.id !== undefined) {
                    getDealAffiliatedParty(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    })
                } else {
                   getByWfNodeId(data.wfNodeId).then(response => {
                      this.form = response.data
                      this.form.fileList = data.fileList
                      this.form.actTitle = data.actTitle
                      // getDealBase(this.dealId).then(res => {
                      //   this.personName = res.data.personChargeName
                      //   this.form.dealPerson = res.data.personCharge
                      //   })
                      this.loading = false
                    })
                    // this.reset()
                    // this.loading = false
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    dealName: undefined,
                    dealId: undefined,
                    companyId: undefined,
                    teamMember: undefined,
                    companyPost: undefined,
                    explain: undefined,
                    createBy: undefined,
                    updateBy: undefined,
                    createTime: undefined,
                    updateTime: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveDealAffiliatedParty(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        }).catch(() => {
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                })
           }
        }
    }
</script>
